yjx.controller('productController', ['$rootScope', '$scope', '$compile', '$state', '$timeout', '$fetch', 'modalService', function ($rootScope, $scope, $compile, $state, $timeout, $fetch, modalService) {
    console.log("========================this is productController")
    var api = '/productCenter/products';
    $scope.keyword = '';
    /*搜索*/
    $scope.search = function () {
        search();
    },
        $scope.searchKey = function ($event) {
            if ($event.keyCode == 13) {
                search()
            }
        }
    function search() {
        if (!$scope.keyword) {
            return true;
        } else {
            $state.go('productList', {keyword: $scope.keyword});
        }
    }

    /*获取tags*/
    function getTagList() {
        $fetch.fetch(
            '/productCenter/tags'
        ).then(function (data) {
                if (data) {
                    $timeout(function () {
                        $scope.tags = data.productTags;
                        //$scope.tagsT = data.productTags.slice(0, 4);
                        //$scope.tagsB = data.productTags.slice(4, 8);
                    })
                } else {
                    modalService("暂时没有分类数据");
                }
            }).catch(function (e) {
                modalService(e.msg);
            })
    }

    getTagList();

    var params = {
        limit: 10,
        offset: 1,
    }
    //$scope.paging = {};
    $scope.pageNum = 1;
    $scope.hideShows = true;
    //$scope._update = false;

    /*初始化获取数据*/
    function getProduct() {
        $fetch.fetch(
            api,
            {
                params: params,
                cache:false,
            }
        ).then(function (data) {
                $timeout(function () {
                    $scope.paging = data.page;
                    $scope.productList = data.rows;
                    //更新状态、数据加载控制
                    $scope._updated = 'reupdated';
                    $scope.hideShows = false;
                })
            }).catch(function (e) {
                modalService.mainMsgError(e.msg);
            })
    }
    getProduct();

    /*翻页处理*/
    $scope.list = function () {
        params.offset = $scope.pageNum;
        $fetch.fetch(
            api,
            {
                params: params,
                cache:false,
            }
        ).then(function (data) {
                $timeout(function () {
                    $scope.paging = data.page;
                    //$scope.productList = data.rows;
                    //if($scope.productList)
                    $scope.productList = $scope.productList.concat(data.rows);
                    //更新状态、数据加载控制
                    $scope._updated = 'updated';
                    $scope.hideShows = false;
                })
            }).catch(function (e) {
                modalService.mainMsgError(e.msg);
            })
    }


}])